<#include "../base/base.ftl">
<@body>
        <div class="wu-toolbar-search" id="tb">
            <a href="#" id="refresh" class="easyui-linkbutton" data-options="iconCls:'icon fa fa-refresh',plain:true">刷新</a>
            <a href="#" id="add" class="easyui-linkbutton" data-options="iconCls:'icon fa fa-plus',plain:true">新增</a>
            <a href="#" id="edit" class="easyui-linkbutton" data-options="iconCls:'icon fa fa-pencil-square-o',plain:true">编辑</a>
            <a href="#" id="del" class="easyui-linkbutton" data-options="iconCls:'icon fa fa-minus-circle',plain:true">删除</a>
            <a href="#" id="review" class="easyui-linkbutton" data-options="iconCls:'icon fa fa-eye',plain:true">审核</a>
            <br>
            <label>名称：</label><input class="wu-text" id="name" style="width:100px">
            <label>电话：</label><input class="wu-text" id="phone" style="width:100px">
            <select id="find_status" panelHeight="auto" style="width:120px" class="easyui-combobox"
                    data-options="editable:false">
                <option value="-2">状态(全部)</option>
                <option value="0">待审核</option>
                <option value="1">已审核</option>
                <option value="-1">审核不通过</option>
            </select>
            <a class="easyui-linkbutton" iconCls="icon-search" onclick="find()">条件搜索</a>
        </div>
    <table id="tt" >
    </table>
    </@body>
    <@js>
    <script type="text/javascript">
    $(function(){
        $('#tt').datagrid({
            singleSelect:true,
            idField:'id',
            rownumbers:true,
            toolbar: '#tb',
            pageSize:20,
            pagination:true,
            fitColumns:true,
            fit:true,
            method:'get',
            url:'/supplier_info/getData',
            onDblClickRow: function(index,field,value){
                $("#edit").click();
            },
            columns:[[
                {field:'name',title:'供应商名称',width:100,sortable:false,align: 'center'},
                {field:'phone',title:'电话',width:100,sortable:false,align: 'center'},
                {field:'supNo',title:'编号',width:100,sortable:false,align: 'center'},
                {field:'company',title:'经营公司',width:80,align:'center'},
                {field:'legalPerson',title:'法人',width:80,align:'center'},
                {field:'busiLicenseNo',title:'营业执照',width:80,align:'center'},
                {field:'legalPersonCard',title:'法人身份证',width:80,align:'center'},
                {field:'status',title:'状态',width:80,align:'center',
                    formatter:function (value,row,index) {
                        var str="";
                        switch (row['status']){
                            case 0:
                                str = '<span style="color: blue;">待审核</span>';
                                break;
                            case 1:
                                str='<span style="color: red">已审核</span>';
                                break;
                            case -1:
                                str='<span style="text-decoration:line-through;">审核不通过</span>';
                                break;
                            default:
                                str=row['status'];
                        }
                        return str;
                    }}
            ]]
        });


        $("#refresh").click(function () {
            $("#tt").datagrid('reload',{});
        });

        $("#edit").click(function () {
            var row=$("#tt").datagrid('getSelected');
            if (row==null){
                com.msg_error("请选择要操作的行");
                return false;
            }
            var id=row.id;
            $("<div></div>").dialog({
                id:'view',
                title:'编辑用户',
                resizable: true,
                closable: true,
                width: 600,
                height: 400,
                modal:true,
                href: "/supplier_info/view?id="+id,
                onClose:function () {
                    $("#view").dialog('destroy');
                },
                onDestroy: function () {
                    $("#tt").datagrid('reload');
                },
                buttons:[{
                    iconCls: 'icon fa fa-check',
                    text: '保存',
                    handler: function () {
                        var index=com.msg_load();
                        $.ajax({
                            type: "POST",
                            url: "/supplier_info/save",
                            data:$("#editForm").serialize(),
                            success: function (data) {
                                com.msg_load_close(index);
                                var d=eval(data);
                                if (data!=null&&d.msg=='success') {
                                    $("#view").dialog('close');
                                    $("#tt").datagrid('reload');
                                    com.msg_success(d.data);
                                } else {
                                    $.messager.progress('close');
                                    com.msg_error(d.msg);
                                }
                            }
                        });
                    }
                }, {
                    text: '关闭',
                    iconCls: 'icon fa fa-times',
                    handler: function () {
                        $("#view").dialog('close');
                    }
                }]
            });
        });

        $("#del").click(function () {
            var row=$("#tt").datagrid('getSelected');
            if (row==null){
                com.msg_error("请选择要操作的行");
                return false;
            };
            var id=row.id;
            com.msg_confirm("确认要删除该用户吗？",function () {
                $.ajax({
                    type: 'POST',
                    url: "/supplier_info/del",
                    data: {id: id},
                    success: function (data) {
                        var d = eval(data);
                        if (data != null && d.msg == 'success') {
                            $("#tt").datagrid('reload');
                            com.msg_success(d.data);
                        } else {
                            com.msg_error(d.msg);
                        }
                    }
                })
            })
        });

        $("#add").click(function () {
            $("<div></div>").dialog({
                id:'addView',
                title:'新增',
                resizable: true,
                closable: true,
                width: 400,
                height: 300,
                modal:true,
                href: "/supplier_info/view",
                onClose:function () {
                    $("#addView").dialog('destroy');
                    $("#tt").datagrid('reload');
                },
                onDestroy: function () {
                    $("#tt").datagrid('reload');
                },
                buttons:[{
                    iconCls: 'icon fa fa-check',
                    text: '保存',
                    handler: function () {
                        var index=com.msg_load();
                        $.ajax({
                            type: "POST",
                            url: "/supplier_info/save",
                            data:$("#editForm").serialize(),
                            success: function (data) {
                                com.msg_load_close(index);
                                var d=eval(data);
                                if (data!=null&&d.msg=='success') {
                                    $("#addView").dialog('close');
                                    $("#tt").datagrid('reload');
                                    com.msg_success(d.data);
                                } else {
                                    $.messager.progress('close');
                                    com.msg_error(d.msg);
                                }
                            }
                        });
                    }
                }, {
                    text: '关闭',
                    iconCls: 'icon fa fa-times',
                    handler: function () {
                        $("#addView").dialog('close');
                    }
                }]
            });

        });


        $("#review").click(function () {
            var row=$("#tt").datagrid('getSelected');
            if (row==null){
                com.msg_error("请选择要操作的行");
                return false;
            }
            var id=row.id;
            $("<div></div>").dialog({
                id:'reviewView',
                title:'审核',
                resizable: true,
                closable: true,
                width: 400,
                height: 300,
                modal:true,
                href: "/supplier_info/view?id="+id,
                onClose:function () {
                    $("#reviewView").dialog('destroy');
                    $("#tt").datagrid('reload');
                },
                onDestroy: function () {
                    $("#tt").datagrid('reload');
                },
                buttons:[{
                    iconCls: 'icon fa fa-check',
                    text: '通过',
                    handler: function () {
                        var index=com.msg_load();
                        $.ajax({
                            type: "POST",
                            url: "/supplier_info/review",
                            data:{id:id,review:1},
                            success: function (data) {
                                com.msg_load_close(index);
                                var d=eval(data);
                                if (data!=null&&d.msg=='success') {
                                    $("#reviewView").dialog('close');
                                    $("#tt").datagrid('reload');
                                    com.msg_success(d.data);
                                } else {
                                    $.messager.progress('close');
                                    com.msg_error(d.msg);
                                }
                            }
                        });
                    }
                }, {
                    text: '不通过',
                    iconCls: 'icon fa fa-times',
                    handler: function () {
                        var index=com.msg_load();
                        $.ajax({
                            type: "POST",
                            url: "/supplier_info/review",
                            data:{id:id,review:-1},
                            success: function (data) {
                                com.msg_load_close(index);
                                var d=eval(data);
                                if (data!=null&&d.msg=='success') {
                                    $("#reviewView").dialog('close');
                                    $("#tt").datagrid('reload');
                                    com.msg_success(d.data);
                                } else {
                                    $.messager.progress('close');
                                    com.msg_error(d.msg);
                                }
                            }
                        });
                    }
                }]
            });

        });
    });

    function find() {
        $('#tt').datagrid('load',{
            name:$('#name').val(),
            phone:$('#phone').val(),
            status:$('#find_status').combobox("getValue")
        })
    }
</script>
    </@js>